fix(crm): require change permission for customer user invites#3847
Merged
Conversation
|
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens authorization around the CRM “Add user to customer” action to prevent read-only staff (with only payments.view_customer) from performing a mutating invite/link operation that grants access to customer self-service data.
Changes:
- Enforce
payments.change_customerbefore executing theadd_customer_userPOST mutation inCustomerDetailView. - Add a
can_add_customer_usercontext flag and hide the add-user form in the customer detail template when the user lacks the change permission. - Add regression tests for read-only staff UI hiding and POST rejection.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
weblate_web/crm/views.py |
Adds a permission guard for the add-customer-user mutation and exposes a context flag for template gating. |
weblate_web/crm/tests.py |
Adds regression tests asserting read-only staff can’t see or perform the add-user action. |
weblate_web/crm/templates/payments/customer_detail.html |
Hides the add-user form unless the view indicates the user has payments.change_customer. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3847 +/- ##
==========================================
- Coverage 88.60% 88.58% -0.02%
==========================================
Files 71 71
Lines 10834 10856 +22
Branches 952 953 +1
==========================================
+ Hits 9599 9617 +18
- Misses 909 913 +4
Partials 326 326 🚀 New features to boost your workflow:
|
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
add_customer_userPOST action while the view was protected only by the read permissionpayments.view_customer, allowing read-only staff to provision/link users to customers.Description
payments.change_customerbefore executing theadd_customer_usermutation by adding acheck_add_customer_user_permissionguard inweblate_web/crm/views.pyand calling it at the start ofadd_customer_user.can_add_customer_userinCustomerDetailView.get_context_datato expose whether the current user has the change permission.weblate_web/crm/templates/payments/customer_detail.htmlunlesscan_add_customer_useris true.weblate_web/crm/tests.pyverifying that a read-only staff user (with onlyview_customer) does not see the form and receives HTTP 403 when POSTing the add action.Testing
pytest -q weblate_web/crm/tests.py -k 'readonly_staff or adds_hosted_user'and the selected tests passed:3 passed, 93 deselected.Codex Task